<?php

namespace App\Http\Controllers\Backend\EdgeManage;

use App\Http\Controllers\Controller;
use App\Http\Repositories\EdgeManage\ProblemRepo;
use App\Http\Requests\Validators\Backend\EdgeManage\ProblemValidator;
use Illuminate\Http\Request;

/**
 * 问题反馈
 */
class ProblemController extends Controller
{
    const VALIDATOR = ProblemValidator::class;

    public function __construct()
    {
        $this->self_repo = new ProblemRepo;
    }

    public function search(Request $request)
    {
        //参数验证
        $args = $request->only('title', 'detail', 'begin_time', 'end_time');
        $this->my_validate($args, 'searchRules');
        return $this->self_repo->search($args);
    }

    public function store(Request $request)
    {
        //参数验证
        $args = $request->only('title', 'detail');
        $this->my_validate($args, 'storeRules');

        $args['user_id'] = $this->getUserId();
        //添加数据
        return $this->returnResponse($this->self_repo->createOne($args));
    }

    public function delete($id)
    {
        return $this->self_repo->deleteById($id);
    }

    public function edit(Request $request, $id)
    {
        //参数验证
        $args = $request->only('title', 'detail');
        $this->my_validate($args, 'editRules');
        //根据id修改数据
        return $this->returnResponse($this->self_repo->editById($id, $args));
    }
}
